<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>商户管理</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  {include file="public/css"/}
</head>
<body>
  <div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-card layui-col-md12">
          <div class="layui-card-header">商户管理{if input('param.isopen')==1}<i class="layui-icon layui-icon-close" style="font-size:18px;font-weight:bold;cursor:pointer" onclick="closeself()"></i>{/if}</div>
          <div class="layui-card-body" pad15>
			  {if $business_num_limit > 0}<blockquote class="layui-elem-quote">商户数量上限：{$business_num_limit}</blockquote>{/if}
						<div class="layui-col-md4" style="padding-bottom:10px">
							<a class="layui-btn layuiadmin-btn-list" href="javascript:void(0)" onclick="openmax('{:url('edit')}')">添加</a>
							<button class="layui-btn layui-btn-primary layuiadmin-btn-list" onclick="datadel(0)">删除</button>
							<!-- <button class="layui-btn layui-btn-primary layuiadmin-btn-list" onclick="setst(0,1)">开启</button>
							<button class="layui-btn layui-btn-primary layuiadmin-btn-list" onclick="setst(0,0)">关闭</button> -->
							<!-- <button class="layui-btn layuiadmin-btn-list" onclick="location.href='?op=excel'+urlEncode(datawhere)">导出</button> -->
							{if getcustom('business_fenxiao')}
							<button class="layui-btn layui-btn-primary layuiadmin-btn-list" data-form-export="{:url('excel')}">导出</button>
							{/if}
							<button class="layui-btn layui-btn-primary layuiadmin-btn-list" onclick="showHexiaoLoginQr()">登录地址</button>
						</div>
						<div class="layui-form layui-col-md8 layui-form-search">
							<div class="layui-inline layuiadmin-input-useradmin">
								<label class="layui-form-label">ID</label>
								<div class="layui-input-inline">
									<input type="text" name="id" autocomplete="off" class="layui-input">
								</div>
							</div>
							<div class="layui-inline layuiadmin-input-useradmin">
								<label class="layui-form-label">名称</label>
								<div class="layui-input-inline">
									<input type="text" name="name" autocomplete="off" class="layui-input">
								</div>
							</div>
							{if $clist}
							<div class="layui-inline">
								<label class="layui-form-label">分类</label>
								<div class="layui-input-inline">
									<select name="cid" lay-search>
										<option value="">全部</option>
										{foreach $clist as $cv}
										<option value="{$cv['id']}">{$cv['name']}</option>
										{/foreach}
									</select>
								</div>
							</div>
							{/if}
							{if getcustom('member_dedamount')}
								<div class="layui-inline">
									<label class="layui-form-label">让利比例审核</label>
									<div class="layui-input-inline">
										<select name="paymoney_givepercent2">
											<option value="">全部</option>
											<option value="0">待审核</option>
											<option value="1">已审核</option>
										</select>
									</div>
								</div>
							{/if}
							<div class="layui-inline">
								<label class="layui-form-label">状态</label>
								<div class="layui-input-inline">
									<select name="status">
										<option value="">全部</option>
										<option value="0">待审核</option>
										<option value="1">已通过</option>
										<option value="2">已驳回</option>
										<option value="-1">已过期</option>
									</select>
								</div>
							</div>
							<div class="layui-inline">
								<label class="layui-form-label">营业状态</label>
								<div class="layui-input-inline">
									<select name="is_open">
										<option value="">全部</option>
										<option value="0">休息</option>
										<option value="1">营业</option>
									</select>
								</div>
							</div>
							<div class="layui-inline">
								<button class="layui-btn layuiadmin-btn-replys" lay-submit="" lay-filter="LAY-app-forumreply-search">
									<i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
								</button>
							</div>
						</div>
						<div class="layui-col-md12">
							<table id="tabledata" lay-filter="tabledata"></table>
						</div>
          </div>
        </div>
    </div>
  </div>
	<div id="rechargeModel" style="width:500px;display:none;margin-top:30px">
		<div class="layui-form" lay-filter="">
			<input type="hidden" name="rechargemid" id="rechargemid"/>
			<div class="layui-form-item">
				<label class="layui-form-label">充值金额</label>
				<div class="layui-input-inline">
					<input type="text" name="rechargemoney" required lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
				</div>
				<div class="layui-form-mid layui-word-aux">输入负值表示扣除金额</div>
			</div>
			<div class="layui-form-item">
				<div class="layui-input-block">
					<button class="layui-btn layui-btn-normal" lay-submit lay-filter="formRecharge">确定充值</button>
				</div>
			</div>
		</div>
	</div>
  <div id="depositModel" style="width:500px;display:none;margin-top:30px">
	  <div class="layui-form" lay-filter="">
		  <input type="hidden" name="depositmid" id="depositmid"/>
		  <div class="layui-form-item">
			  <label class="layui-form-label">充值金额</label>
			  <div class="layui-input-inline">
				  <input type="text" name="depositmoney" required lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
			  </div>
			  <div class="layui-form-mid layui-word-aux">输入负值表示扣除金额</div>
		  </div>
		  <div class="layui-form-item">
			  <label class="layui-form-label">备注</label>
			  <div class="layui-input-inline">
				  <input type="text" name="depositremark" lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
			  </div>
			  <div class="layui-form-mid layui-word-aux"></div>
		  </div>
		  <div class="layui-form-item">
			  <div class="layui-input-block">
				  <button class="layui-btn layui-btn-normal" lay-submit lay-filter="formdeposit">确定充值</button>
			  </div>
		  </div>
	  </div>
  </div>
	{include file="public/js"/}
	<script>
	var shopsel = false;
	var restaurantsel = false;
  var table = layui.table;
	var datawhere = {};
  //数据表
  var tableIns = table.render({
    elem: '#tabledata'
    ,url: "{$Request.url}" //数据接口
    ,page: true //开启分页
	  ,autoSort:false
    ,cols: [[ //表头
			{type:"checkbox"},
      {field: 'id', title: 'ID',  sort: true,width:80},
      {field: 'cname', title: '商家分类'},
      {field: 'name', title: '商家名称'},
      {field: 'logo', title: '商家图片',templet:function(d){return '<img src="'+d.logo+'" style="width:80px;"/>';},width: 100},
      {field: 'address', title: '商家地址'},
      {field: 'nickname', title: '头像昵称',templet:function(d){
				if(!d.nickname) return '';
				var html = '';
				if(d.headimg){
			        html +='<img src="'+d.headimg+'" style="width:40px;height:40px"/>';
		  		}
			  	html += d.nickname;
				return html;
      }},
      {field: 'linkman', title: '联系人',templet:function(d){ return d.linkman + '('+d.linktel+')' }},
			{field: 'money', title: "余额",templet:function(d){
				return '<a href="javascript:void(0)" onclick="openmax(\'{:url('BusinessMoney/moneylog')}&isopen=1&bid='+d.id+'\')">'+d.money+'</a>';
			},sort:true},
		  {if getcustom('business_deposit')}
		  {field: 'money', title: "{:t('入驻保证金')}",templet:function(d){
		  	  	 var html = '<div><a href="javascript:void(0)" onclick="openmax(\'{:url('BusinessMoney/depositlog')}&isopen=1&bid='+d.id+'\')">'+d.deposit+'</a></div>';
				  {if getcustom('business_deposit_refund')}
				  		if(d.deposit_refund_status ==1){
html+='<div><a href="javascript:void(0)" onclick="checkdepositrefund('+d.deposit_orderid+')"  style="color: red">退款申请</a></div>';
			  			}
				  {/if}
				return html;
			  },sort:true},
		  {/if}
			  
		  {if getcustom('business_maidan_team_fenhong')}
		  {field: 'money', title: "收款买单金额",templet:function(d){
		  			var html = '<div style="color: #1E9FFF">￥'+d.maidan_money+'</div>';
				  	if(d.maidan_fenhong_jl_minprice<=0){
					  html+='<div style="color: red">未设置</div>';
			  		}else{
					  if(d.is_maidan_fenhong ==1){
						  html+='<div style="color: green">已达标</div>';
					  }else{
						  html+='<div style="color: red">不达标</div>';
					  }
			  		}
				return html;
		   }},
		  {/if}
			  
			{if $bset['business_selfscore']==1}
			{field: 'score', title: "{:t('积分')}",templet:function(d){
				return '<a href="javascript:void(0)" onclick="openmax(\'{:url('BusinessScore/scorelog')}&isopen=1&bid='+d.id+'\')">'+d.score+'</a>';
			},sort:true},
			{/if}
			{if getcustom('blist_showadminnum')}
			{field: 'adminnum', title: '店员数'},
			{/if}
			{if getcustom('business_sales_quota')}
			{field: 'total_sales_quota', title: '已销售额度'},
			{field: 'syquota', title: '剩余销售额度'},
			{/if}
			{field: 'viewnum', title: '浏览量',width:70},
      {field: 'createtime', title: '创建时间',templet:function(d){ return date('Y-m-d H:i',d.createtime)},sort:true},
		  {field: 'endtime', title: '到期时间',templet:function(d){ return date('Y-m-d',d.endtime)},sort:true},
		  {if getcustom('business_pc_yeji_ranking')}
		 	 {field: 'yeji', title: '业绩',templet:function(d){ return d.yeji},sort:true},
		  {/if}
		  {if getcustom('member_dedamount')}
		 	 {field: 'paymoney_givepercent', title: '让利比例',templet:function(d){ 
		 	 	var html = '';
		 	 		html += '<div>'+d.paymoney_givepercent+'%</div>';
		 	 		if(d.paymoney_givepercent2 >=0){
		 	 			html += '<div style="color:red">待审核：'+d.paymoney_givepercent2+'%</div>';
		 	 			html += '<button class="table-btn" onclick="setPaymoneyGivepercent(\''+d.id+'\',1)">通过</button>';
		 	 			html += '<button class="table-btn" onclick="setPaymoneyGivepercent(\''+d.id+'\',2)">驳回</button>';
		 	 		}
		 	 	return html;
		 	 },sort:true},
		  {/if}
		  {if getcustom('business_expert')}
		 	 {field: 'expertid', title: '达人信息',templet:function(d){
		 	 	var html = '';
		 	 	if(d.expertid){
		 	 		var expertinfo = d.expert?d.expert.linkman:'';
		 	 		html += '<a href="javascript:void(0)" onclick="openmax(\'{:url('BusinessExpert/index')}&isopen=1&id='+d.expertid+'\')">'+expertinfo+'(ID:'+d.expertid+')'+'</a>';
		 	 	}
		 	 	return html;
       }},
		  {/if}
      {field: 'status', title: '状态',templet:function(d){ 
				if(d.status==0){
					return '<span style="color:red">待审核</span>';
				}else if(d.status==1){
					return '<span style="color:green">已通过</span>';
				}else if(d.status==2){
					return '<span style="color:red">已驳回</span>';
				}else if(d.status==-1){
					return '<span style="color:red">已过期</span>';
				}
			}},
		  {field: 'is_open', title: '营业状态',templet:function(d){
				  if(d.is_open==0){
					  return '<span style="color:red">休息</span>';
				  }else if(d.is_open==1){
					  return '<span style="color:green">营业</span>';
				  }
			  }},
      {field: 'operation', title: '操作',templet: function(d){
				var html = '';
				html += '<button class="table-btn" onclick="openmax(\'{:url('edit')}/id/'+d.id+'\')">编辑</button>';
				html += '<button class="table-btn" onclick="datadel('+d.id+')">删除</button>';
			  {if $isadmin!=3}
				html += '<button class="table-btn" onclick="recharge('+d.id+')">充值</button>';
			  {/if}
				{if $bset['business_selfscore']==1}
				html += '<button class="table-btn" onclick="addscore('+d.id+')">加{:t('积分')}</button>';
				{/if}
				{if getcustom('business_deposit')}
				html += '<button class="table-btn" onclick="adddeposit('+d.id+')">加{:t('入驻保证金')}</button>';
				{/if}
				html += '<button class="table-btn" onclick="blogin('+d.id+')">登录</button>';
				if(d.status == 0 || d.status == 2){
					html += '<button class="table-btn" onclick="setcheckst(\''+d.id+'\',1)">通过</button>';
				}
				if(d.status == 0 || d.status == 1){
					html += '<button class="table-btn" onclick="setcheckst(\''+d.id+'\',2)">驳回</button>';
				}
				html += '<button class="table-btn" onclick="copydata(\''+d.id+'\')">复制数据</button>';
				{if getcustom('plug_businessqr')}
				html += '<button class="table-btn" onclick="openmax(\'{:url('PlugBusinessqrPay/index')}&bid='+d.id+'\')">快捷支付</button>';
				{/if}
				{if getcustom('restaurant_product_import')}	
					{if $isadminlogin}
						if(d.restaurant_auth){
						html += '<button class="table-btn" onclick="showChooseRestaurantProduct(\''+d.id+'\')">导入菜品</button>';
						}
					{/if}
				{/if}
				{if getcustom('alipay_fenzhang')}
					{if $bset['alifw_status'] == 1 && ( $auth_data=='all' || in_array('alipayFenzhang',$auth_data))}
					html += '<button class="table-btn" onclick="alipayset(\''+d.id+'\')">支付宝收款</button>';
					{/if}
				{/if}	
				return html;
      },width:250}
    ]]
  });
	var rechargelayer
	function recharge(id){
		$('#rechargemid').val(id);
		rechargelayer = layer.open({type:1,area: ['500px', '200px'],title:"{:t('余额')}充值",content:$('#rechargeModel'),shadeClose:true})
	}
	
	function showChooseRestaurantProduct(bid){
		{if getcustom('restaurant_product_import')}
		layer.open({type:2,title:'选择商品',content:"{:url('RestaurantProduct/chooseproduct')}/is_import/1/bid/"+bid,area:['1000px','600px'],shadeClose:true});
		{/if}
	}
	function addscore(id){
		var html = '';
		html+='	<div class="layui-form-item" style="margin-top:40px;margin-right:20px;">';
		html+='		<label class="layui-form-label" style="width:80px">增加数量：</label>';
		html+='		<div class="layui-input-inline" style="width:200px">';
		html+='			<input type="text" id="addscorescore" class="layui-input"/>';
		html+='		</div>';
		html+='		<div class="layui-form-mid layui-word-aux">输入负值表示扣除{:t('积分')}</div>';
		html+='	</div>';
		html+='	<div class="layui-form-item" style="margin-top:40px;margin-right:20px;">';
		html+='		<label class="layui-form-label" style="width:80px">备注信息：</label>';
		html+='		<div class="layui-input-inline" style="width:350px">';
		html+='			<input type="text" id="addscoreremark" class="layui-input"/>';
		html+='		</div>';
		html+='	</div>';
		var addscoreLayer = layer.open({type:1,area:['500px','300px'],title:false,content:html,shadeClose:true,btn: ['确定', '取消'],
			yes:function(){
				var index = layer.load();
				$.post("{:url('addscore')}",{id:id,score:$('#addscorescore').val(),remark:$('#addscoreremark').val()},function(res){
					layer.close(index);
					dialog(res.msg,res.status);
					layer.close(addscoreLayer);
					tableIns.reload()
				})
			}
		})
	}

	function blogin(id){
		window.open("{:url('blogin')}/id/"+id);
	}
	//充值提交
  layui.form.on('submit(formRecharge)', function(obj){
		var index= layer.load();
    $.post("{:url('recharge')}",obj.field,function(data){
			layer.close(index);
			dialog(data.msg,data.status,data.url);
			if(data.status==1){
				tableIns.reload({
					where: datawhere
				});
			}
			layer.close(rechargelayer);
		})
  });
			  var depositlayer
			  function adddeposit(id){
				  $('#depositmid').val(id);
				  depositlayer = layer.open({type:1,area: ['500px', '300px'],title:"保证金充值",content:$('#depositModel'),shadeClose:true})
			  }

			  //充值提交
			  layui.form.on('submit(formdeposit)', function(obj){
				  var index= layer.load();
				  $.post("{:url('deposit')}",obj.field,function(data){
					  layer.close(index);
					  dialog(data.msg,data.status,data.url);
					  if(data.status==1){
						  tableIns.reload({
							  where: datawhere
						  });
					  }
					  layer.close(depositlayer);
				  })
			  });
	//排序
	table.on('sort(tabledata)', function(obj){
		datawhere.field = obj.field;
		datawhere.order = obj.type;
		tableIns.reload({
			initSort: obj,
			where: datawhere
		});
	});
	//检索
	layui.form.on('submit(LAY-app-forumreply-search)', function(obj){
		var field = obj.field
		var olddatawhere = datawhere
		datawhere = field
		datawhere.field = olddatawhere.field
		datawhere.order = olddatawhere.order
		tableIns.reload({
			where: datawhere,
			page: {curr: 1}
		});
	})
	
	//审核
	function setcheckst(id,st){
		if(st == 2){
			var html = '';
			html+='	<div class="layui-form-item" style="margin-top:40px;margin-right:20px;">';
			html+='		<label class="layui-form-label" style="width:80px">驳回原因</label>';
			html+='		<div class="layui-input-inline" style="width:350px">';
			html+='			<textarea type="text" id="check_reason" class="layui-textarea"></textarea>';
			html+='		</div>';
			html+='	</div>';
			var checkLayer = layer.open({type:1,area:['500px','250px'],title:false,content:html,shadeClose:true,btn: ['确定', '取消'],
				yes:function(){
					var index = layer.load();
					$.post("{:url('setcheckst')}",{id:id,st:st,reason:$('#check_reason').val()},function(res){
						layer.close(index);
						dialog(res.msg,res.status);
						layer.close(checkLayer);
						tableIns.reload()
					})
				}
			})
		}else{
			layer.confirm('确定要审核通过吗?',{icon: 7, title:'操作确认'}, function(index){
				layer.close(index);
				var index = layer.load();
				$.post("{:url('setcheckst')}",{id:id,st:st},function(data){
					layer.close(index);
					dialog(data.msg,data.status);
					tableIns.reload()
				})
			});
		}
	}
	//删除
	function datadel(id){
		var ids = [];
		if(id==0){
			var checkStatus = table.checkStatus('tabledata')
			var checkData = checkStatus.data; //得到选中的数据
			if(checkData.length === 0){
				 return layer.msg('请选择数据');
			}
			for(var i=0;i<checkData.length;i++){
				ids.push(checkData[i]['id']);
			}
		}else{
			ids.push(id);
		}
		layer.confirm('删除商家后，该商家下的商品、订单等会一并删除，确定要删除吗？删除后无法恢复！',{icon: 7, title:'操作确认'}, function(index){
			//do something
			layer.close(index);
			var index = layer.load();
			$.post("{:url('del')}",{ids:ids},function(data){
				layer.close(index);
				dialog(data.msg,data.status);
				tableIns.reload()
			})
		});
	}
	//上下架
	function setst(id,st){
		var ids = [];
		if(id==0){
			var checkStatus = table.checkStatus('tabledata')
			var checkData = checkStatus.data; //得到选中的数据
			if(checkData.length === 0){
				 return layer.msg('请选择数据');
			}
			for(var i=0;i<checkData.length;i++){
				ids.push(checkData[i]['id']);
			}
		}else{
			ids.push(id);
		}
		layer.confirm('确定要'+(st==0?'关闭':'开启')+'吗?',{icon: 7, title:'操作确认'}, function(index){
			//do something
			layer.close(index);
			var index = layer.load();
			$.post("{:url('setst')}",{ids:ids,st:st},function(data){
				layer.close(index);
				dialog(data.msg,data.status);
				tableIns.reload()
			})
		});
	}
	function showHexiaoLoginQr(){
		layer.open({type:1,area:['500px','450px'],content:'<div style="margin-top:40px;text-align:center"><div style="margin:20px 110px;text-align:center" id="hexiaologinqr"></div><div style="font-size:30px;color:#e94745"><span style="font-size:24px"></span></div><div style="font-size:14px;text-align:center;margin:10px 20px">手机端：{:m_url('admin/index/index')}</div><div style="font-size:14px;text-align:center;margin:10px 20px">电脑端：{$Think.const.PRE_URL}</div></div>',title:false,shadeClose:true});
		var qrcode = new QRCode('hexiaologinqr', {
			text: 'your content',
			width: 280,
			height: 280,
			colorDark : '#000000',
			colorLight : '#ffffff',
			correctLevel : QRCode.CorrectLevel.H
		});
		qrcode.clear();
		qrcode.makeCode("{:m_url('admin/index/index')}");
	}

	//复制数据
	function copydata(id){
		var html = '';
		html ='<div style="margin:20px auto;">';
		html+='	<blockquote class="layui-elem-quote" style="margin:10px">复制操作会对复制到的商户的数据产生较大影响，请提前做好备份</blockquote>';
		html+='	<div class="layui-form" lay-filter="">';
		html+='		<div class="layui-form-item">';
		html+='			<label class="layui-form-label" style="width:130px">复制到的商户ID：</label>';
		html+='			<div class="layui-input-inline">';
		html+='				<input type="text" name="info[toid]" value="'+id+'" required lay-verify="required" placeholder="" autocomplete="off" class="layui-input">';
		html+='			</div>';
		html+='		</div>';
		html+='		<div class="layui-form-item">';
		html+='			<label class="layui-form-label" style="width:130px">要复制的数据：</label>';
		html+='			<div class="layui-input-block" style="margin-left:150px;">';
		html+='				<div style="margin-top:10px;color:#303030; font-size:14px; font-weight:600; ">';
		html+='					<input type="checkbox" title="全部选择" lay-skin="primary" lay-filter="checkall_all"/>';
		html+='				</div>';
		html+='				<div style="float:left;margin-left:0">';
		html+='					<div style="margin-left:10px">';
		{if $auth_data=='all' || in_array('ShopProduct/*',$auth_data)}
		html+='						<div style="min-width:100px;float: left;">';
		html+='							<input type="checkbox" value="商城商品" name="module_data[]"  title="商城商品" lay-skin="primary" lay-filter="shopset"/>';
		html+='						</div>';
		{/if}
		{if $auth_data=='all' || in_array('CollageProduct/*',$auth_data)}
		html+='						<div style="min-width:100px;float: left;">';
		html+='							<input type="checkbox" value="拼团商品" name="module_data[]"  title="拼团商品" lay-skin="primary"/>';
		html+='						</div>';
		{/if}
		{if $auth_data=='all' || in_array('KanjiaProduct/*',$auth_data)}
		html+='						<div style="min-width:100px;float: left;">';
		html+='							<input type="checkbox" value="砍价商品" name="module_data[]"  title="砍价商品" lay-skin="primary"/>';
		html+='						</div>';
		{/if}
		{if $auth_data=='all' || in_array('SeckillProduct/*',$auth_data)}
		html+='						<div style="min-width:100px;float: left;">';
		html+='							<input type="checkbox" value="秒杀商品" name="module_data[]"  title="秒杀商品" lay-skin="primary"/>';
		html+='						</div>';
		{/if}
		{if $auth_data=='all' || in_array('TuangouProduct/*',$auth_data)}
		html+='						<div style="min-width:100px;float: left;">';
		html+='							<input type="checkbox" value="团购商品" name="module_data[]"  title="团购商品" lay-skin="primary"/>';
		html+='						</div>';
		{/if}
		{if $auth_data=='all' || in_array('LuckyCollageProduct/*',$auth_data)}
		html+='						<div style="min-width:100px;float: left;">';
		html+='							<input type="checkbox" value="{:t(\'幸运拼团\')}商品" name="module_data[]"  title="{:t(\'幸运拼团\')}商品" lay-skin="primary"/>';
		html+='						</div>';
		{/if}
		{if $auth_data=='all' || in_array('Shortvideo/*',$auth_data)}
		html+='						<div style="min-width:100px;float: left;">';
		html+='							<input type="checkbox" value="短视频" name="module_data[]"  title="短视频" lay-skin="primary"/>';
		html+='						</div>';
		{/if}
		{if $auth_data=='all' || in_array('Article/*',$auth_data)}
		html+='						<div style="min-width:100px;float: left;">';
		html+='							<input type="checkbox" value="文章列表" name="module_data[]"  title="文章列表" lay-skin="primary"/>';
		html+='						</div>';
		{/if}
		{if $auth_data=='all' || in_array('Yuyue/*',$auth_data)}
		html+='						<div style="min-width:100px;float: left;">';
		html+='							<input type="checkbox" value="预约服务商品" name="module_data[]"  title="预约服务商品" lay-skin="primary"/>';
		html+='						</div>';
		{/if}
		{if $auth_data=='all' || in_array('KechengList/*',$auth_data)}
		html+='						<div style="min-width:100px;float: left;">';
		html+='							<input type="checkbox" value="知识付费课程" name="module_data[]"  title="知识付费课程" lay-skin="primary"/>';
		html+='						</div>';
		{/if}
		{if $auth_data=='all' || in_array('Restaurant/*',$auth_data)}
		html+='						<div style="min-width:100px;float: left;">';
		html+='							<input type="checkbox" value="餐饮菜品" name="module_data[]"  title="餐饮菜品" lay-skin="primary" lay-filter="restaurantset"/>';
		html+='						</div>';
		{/if}
		{if $auth_data=='all' || in_array('ShopCategory/*',$auth_data)}
		html+='						<div style="min-width:100px;float: left;">';
		html+='							<input type="checkbox" value="商城商品分类" name="module_data[]"  title="商城商品分类" lay-skin="primary"/>';
		html+='						</div>';
		{/if}
		{if $auth_data=='all' || in_array('Coupon/*',$auth_data)}
		html+='						<div style="min-width:100px;float: left;">';
		html+='							<input type="checkbox" value="优惠券" name="module_data[]"  title="优惠券" lay-skin="primary"/>';
		html+='						</div>';
		{/if}
		{if getcustom('form_copy')}
			{if $auth_data=='all' || in_array('Form/*',$auth_data)}
			html+='						<div style="min-width:100px;float: left;">';
			html+='							<input type="checkbox" value="自定义表单" name="module_data[]"  title="自定义表单" lay-skin="primary"/>';
			html+='						</div>';
			{/if}
		{/if}
		{if getcustom('extend_gift_bag')}
			{if $auth_data=='all' || in_array('GiftBag/*',$auth_data)}
			html+='						<div style="min-width:100px;float: left;">';
			html+='							<input type="checkbox" value="礼包" name="module_data[]"  title="礼包" lay-skin="primary"/>';
			html+='						</div>';
			{/if}
		{/if}
		//html+='						<div style="min-width:100px;float: left;">';
		//html+='							<input type="checkbox" value="设计页面" name="module_data[]"  title="设计页面" lay-skin="primary"/>';
		//html+='						</div>';
		html+='					</div>';
		html+='				</div>';
		html+='			</div>';
		html+='		</div>';
		{if getcustom('business_copy_shopcategory')}
			{if $auth_data=='all' || in_array('ShopCategory/*',$auth_data)}
			html+='<div class="layui-form-item" style="display:none;margin-top:50px" id="shopcat">';
			html+='	<label class="layui-form-label" style="width:130px">商品分类：</label>';
			html+='	<div class="layui-input-inline" style="width:400px">';
			html+='		<select name="info[shopcids]" id="cid" xm-select="selectShopCid" xm-select-max="" xm-select-search >';
			html+='			<option value="">--全部--</option>';
									{foreach $shopclist as $cv}
			html+='			<option value="{$cv['id']}" >{$cv['name']}</option>';
										{foreach $cv['child'] as $k=>$v}
											{if $k < count($cv['child'])-1}
			html+='					<option value="{$v['id']}" >&nbsp;&nbsp;&nbsp;&nbsp;├ {$v['name']}</option>';
											{else}
			html+='					<option value="{$v['id']}" >&nbsp;&nbsp;&nbsp;&nbsp;└ {$v['name']}</option>';
											{/if}
											{foreach $v['child'] as $k2=>$v2}
												{if $k2 < count($v['child'])-1}
			html+='						<option value="{$v2['id']}">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;├ {$v2['name']}</option>';
												{else}
			html+='						<option value="{$v2['id']}">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;└ {$v2['name']}</option>';
												{/if}
											{/foreach}
										{/foreach}
									{/foreach}
			html+='		</select>';
			html+='	</div>';
			html+='	<div class="layui-form-mid layui-word-aux">不选择默认全部</div>';
			html+='</div>';
			{/if}
		{/if}
		{if getcustom('business_copy_restaurantcategory')}
			{if $auth_data=='all' || in_array('RestaurantProductCategory/*',$auth_data)}
			html+='<div class="layui-form-item" style="display:none;margin-top:50px" id="restaurantcat">';
			html+='	<label class="layui-form-label" style="width:130px">餐饮分类：</label>';
			html+='	<div class="layui-input-inline" style="width:400px">';
			html+='		<select name="info[restaurantcids]" id="cid" xm-select="selectRestauranCid" xm-select-max="" xm-select-search >';
			html+='			<option value="">--全部--</option>';
									{foreach $restaurantclist as $rv}
			html+='			<option value="{$rv['id']}" >{$rv['name']}</option>';
										{foreach $rv['child'] as $k=>$v}
											{if $k < count($rv['child'])-1}
			html+='					<option value="{$v['id']}" >&nbsp;&nbsp;&nbsp;&nbsp;├ {$v['name']}</option>';
											{else}
			html+='					<option value="{$v['id']}" >&nbsp;&nbsp;&nbsp;&nbsp;└ {$v['name']}</option>';
											{/if}
											{foreach $v['child'] as $k2=>$v2}
												{if $k2 < count($v['child'])-1}
			html+='						<option value="{$v2['id']}">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;├ {$v2['name']}</option>';
												{else}
			html+='						<option value="{$v2['id']}">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;└ {$v2['name']}</option>';
												{/if}
											{/foreach}
										{/foreach}
									{/foreach}
			html+='		</select>';
			html+='	</div>';
			html+='	<div class="layui-form-mid layui-word-aux">不选择默认全部</div>';
			html+='</div>';
			{/if}
		{/if}
		html+='		<div class="layui-form-item">';
		html+='			<label class="layui-form-label" style="width:130px">删除原有数据：</label>';
		html+='			<div class="layui-input-inline">';
		html+='				<input type="radio" name="info[delold]" value="0" title="否" checked>';
		html+='				<input type="radio" name="info[delold]" value="1" title="是">';
		html+='			</div>';
		html+='			<div class="layui-form-mid layui-word-aux">是否删除掉要复制到的商户的原来的数据</div>';
		html+='		</div>';
		html+='		<div class="layui-form-item" style="margin-top:40px">';
		html+='			<label class="layui-form-label" style="width:130px"></label>';
		html+='			<div class="layui-input-block">';
		html+='				<button class="layui-btn layui-btn-normal" lay-submit lay-filter="formCopydata">确定复制</button>';
		html+='			</div>';
		html+='		</div>';
		html+='	</div>';
		html+='</div>';
		{if getcustom('business_copy_shopcategory')}
			shopsel = false;
			$('#shopcat').hide();
		{/if}
		{if getcustom('business_copy_restaurantcategory')}
			restaurantsel = false;
			$('#restaurantcat').hide();
		{/if}
		var copydatalayer = layer.open({type:1,area:['800px','800px'],content:html,title:'平台数据复制到商户',shadeClose:true});
		layui.formSelects.render();
		layui.form.render();
		layui.form.on('submit(formCopydata)', function(obj){
			var field = obj.field;
			console.log(field);
			var index= layer.load();
			$.post("{:url('copydata')}",field,function(data){
				layer.close(index);
				dialog(data.msg,data.status);
				if(data.status == 1){
					{if getcustom('business_copy_shopcategory')}
						shopsel = false;
						$('#shopcat').hide();
					{/if}
					{if getcustom('business_copy_restaurantcategory')}
						restaurantsel = false;
						$('#restaurantcat').hide();
					{/if}
					layer.close(copydatalayer);
				}
			})
		})
		layui.form.on('checkbox(checkall_all)',function(data){
			if(data.elem.checked){
				$(data.elem).parent().parent().find('input[type=checkbox]').prop('checked',true);
				{if getcustom('business_copy_shopcategory')}
					shopsel = true;
					$('#shopcat').show();
				{/if}
				{if getcustom('business_copy_restaurantcategory')}
					restaurantsel = true;
					$('#restaurantcat').show();
				{/if}
			}else{
				$(data.elem).parent().parent().find('input[type=checkbox]').prop('checked',false);
				{if getcustom('business_copy_shopcategory')}
					shopsel = false;
					$('#shopcat').hide();
				{/if}
				{if getcustom('business_copy_restaurantcategory')}
					restaurantsel = false;
					$('#restaurantcat').hide();
				{/if}
			}

			layui.form.render('checkbox'); 
		});
		layui.form.on('checkbox(checkall)',function(data){
			if(data.elem.checked){
				$(data.elem).parent().parent().find('input[type=checkbox]').prop('checked',true);
			}else{
				$(data.elem).parent().parent().find('input[type=checkbox]').prop('checked',false);
			}
			layui.form.render('checkbox'); 
		})
	}

	{if getcustom('zhaopin')}
		function openZhaopin(bid){
			$.post("{:url('zhaopin/openZhaopin')}",{bid:bid},function(data){
				dialog(data.msg,data.status);
				if(data.status == 1){
					layer.close(copydatalayer);
				}
			})
		}
	{/if}
	{if getcustom('business_copy_shopcategory')}
			layui.form.on('checkbox(shopset)',function(data){
				shopsel = !shopsel;
				if(shopsel){
					$('#shopcat').show();
				}else{
					$('#shopcat').hide();
				}
			})
	{/if}
	{if getcustom('business_copy_restaurantcategory')}
			layui.form.on('checkbox(restaurantset)',function(data){
				restaurantsel = !restaurantsel;
				if(restaurantsel){
					$('#restaurantcat').show();
				}else{
					$('#restaurantcat').hide();
				}
			})
	{/if}
	//显示退款订单	
	function showDepositOrder(orderid){
		var index_load = layer.load();
		$.post("{:url('getdepositorder')}",{orderid:orderid},function(data) {
			tuikuandata = data;
			layer.close(index_load);
			layui.laytpl(ordertpl.innerHTML).render(data, function(html){
				var refundLayer = layer.open({type:1,title:'退款详情',area:'500px',content:html,resize:true,shadeClose:true,maxmin:true,btn: ['确定', '取消'],
					yes:function(){
						var reason = $('#tuireason').val();
						var refundNum = [];
						var money = $('#refund_money').val();
						$(".refundNum").each(function(){
							refundNum.push({ogid:$(this).attr('data-ogid'),num:$(this).val()})
						});
						var refund_type = $("input[name=refund_type]").val();
						// console.log(refund_type);return;
						if(reason == '') {
							layer.msg('请填写退款原因');return false;
						}
						if(money < 0) {
							layer.msg('请输入正确的退款金额');return false;
						}

						var index = layer.load();
						$.post("{:url('refund')}",{orderid:orderid},function(res){
							layer.close(index);
							dialog(res.msg,res.status);
							layer.close(refundLayer);
							layer.close(detailLayer);
							tableIns.reload()
						})
					}
				})
			});
		});
	}

	function checkdepositrefund(orderid){

		var html = '';
		html+='	<div  style="padding: 20px 20px;text-align: center">';
		html+='审核通过后，商户保证金将清零，请线下支付给商户';
		html+='	</div>';
		var checkLayer = layer.open({type:1,area:['400px','120px'],title:false,content:html,shadeClose:true,btn: ['通过', '驳回'],
			btn1:function(){
				var index = layer.load();
				$.post("{:url('setdepositrefund')}",{orderid:orderid,st:2},function(res){
					if(res.code ==0){
						layer.error(res.msg);
					}
					layer.close(index);
					dialog(res.msg,res.status);
					layer.close(checkLayer);
					tableIns.reload()
				})
			},	btn2:function(){
				var index = layer.load();
				$.post("{:url('setdepositrefund')}",{orderid:orderid,st:3},function(res){
					if(res.code ==0){
						layer.error(res.msg);
					}
					layer.close(index);
					dialog(res.msg,res.status);
					layer.close(checkLayer);
					tableIns.reload()
				})
			}
		})
		
	}
	{if getcustom('alipay_fenzhang')}
	var makelayer = null;
	function alipayset(id) {
		layer.close(makelayer)
		var index = layer.load();
		$.get("{:url('alipaySet')}",{id:id},function(res){
			var data = res.data; 
			layer.close(index);
		
			var alipayst1 = data.alipayst =='1'?'checked':'';
			var alipayst0 = data.alipayst =='0'?'checked':'';
			console.log(alipayst1);
			console.log(alipayst0,'alipayst0');
			var html = '<div style="margin:20px auto;">';
			html+='<div class="layui-form" lay-filter="">';
			html+=' <input type="hidden" class="layui-input"  name="id" value="'+data.id+'" disabled="true">';
			
			html+=' <div class="layui-form-item">';
			html+='   <label class="layui-form-label" style="width:150px">独立收款：</label>';
			html+='   <div class="layui-input-inline" style="width:300px">';
			html+='     <input type="radio" name="alipayst" '+alipayst1+' value="1" title="开启"/>';
			html+='     <input type="radio" name="alipayst" '+alipayst0+' value="0"  title="关闭"/>';
			html+='   </div>';
			html+='  <div class="layui-form-mid" style="margin-left:180px;display: block">开启后，服务商代商家收款，且开启分账，请在[控制台]-[第三方应用]中配置第三方应用信息。</div>';
			html+=' </div>';
			
			html+=' <div class="layui-form-item">';
			html+='   <label class="layui-form-label" style="width:150px">APPID：</label>';
			html+='   <div class="layui-input-inline" style="width:300px;display: flex">';
			html+='     <input type="text" class="layui-input" name="alipayappid" value="'+data.alipayappid+'" >';
			html+='     <button class="layui-btn layui-btn-primary" onclick="alipayIsvAuth(this)">授权</button>';
			if(data.alipay_app_auth_token){
				html+='     <div style="width: 100px; line-height: 40px;margin-left: 10px;color: green;">已授权</div>';
			}
	
			html+='   </div>';
			html+='  <div class="layui-form-mid" style="margin-left:180px;display: block">商家应用的APPID,登录<a href="https://b.alipay.com" target="_blank">商家平台</a>在[账号中心]-[APPID绑定]-[已绑定应用]中查找需要授权的APPID。</div>';
			html+=' </div>';


			html+=' <div class="layui-form-item" style="margin-top:20px">';
			html+='   <label class="layui-form-label" style="width:150px">授权token：</label>';
			html+='   <div class="layui-input-inline" style="width:300px;display: flex">';
			html+='     <input type="text" class="layui-input" name="alipay_app_auth_token" value="'+data.alipay_app_auth_token+'" >';
			html+='   </div>';
			html+='  <div class="layui-form-mid" style="margin-left:180px;display: block">可进入支付宝<a href="https://open.alipay.com/" target="_blank">开放平台</a>在[商家授权]-[邀请商家授权]后复制粘贴[授权token]。</div>';
			html+=' </div>';
			
			html+=' <div class="layui-form-item" style="margin-top:30px">';
			html+='   <label class="layui-form-label" style="width:150px"></label>';
			html+='   <div class="layui-input-inline">';
			html+='     <button class="layui-btn layui-btn-success" data-type="refresh"  lay-submit lay-filter="submit_alipay">刷 新</button>';
			html+='     <button class="layui-btn layui-btn-normal" data-type="submit" lay-submit lay-filter="submit_alipay">确 定</button>';
			html+='   </div>';
			html+=' </div>';
			
			html+='</div>';
			html+='</div>'
			 makelayer = layer.open({type:1,area: ['45%', '480px'],title:'支付宝独立收款',content:html,shadeClose:true})
			layui.form.render();
			layui.form.on('submit(submit_alipay)', function(obj){
			
				var type = $(this).attr('data-type');
				var field = obj.field;
				var index= layer.load();
				$.post("{:url('alipaySet')}",field,function(data){
					layer.close(index);
					if(type =='submit'){
						dialog(data.msg,data.status,data.url)
					}
					if(data.status == 1){
						layer.close(makelayer)
						if(type =='refresh'){
							alipayset(id);
						}
						tableIns.reload()
					}
				})
			})
		})
		
	}
		function alipayIsvAuth(){
			var alipayappid  = $('#alipayappid').val();
			if(alipayappid ==''){
				dialog("请输入Appid");
				return;
			}
			var index = layer.load();
			$.post("{:url('alipayIsvAuthorization')}", {appid:alipayappid},function(res){
				layer.close(index);
				if(res.status == 1){
					var html = '';
					html += '<div style="margin:auto auto;text-align:center">';
					html += '<img src="'+res.data+'" style="margin-top:20px;max-width:280px;max-height:280px"/>';
					html += '<div style="height:25px;line-height:25px;">商家使用【支付宝客户端】扫描二维码授权</div>';
					html += '</div>';
					loginlayer = layer.open({type:1,area:['300px','350px'],content:html,title:false,shadeClose:false,cancel:function(){
							//clearInterval(timer);
						}});
				}else{
					dialog(res.msg,res.status);
				}
			})
		}
		function refresh(id){
			
		}
	{/if}
	{if getcustom('member_dedamount')}
		function setPaymoneyGivepercent(id,st){
				if(st == 1){
					var msg = '确定要通过让利比例吗?';
				}else{
					var msg = '确定要驳回让利比例吗?';
				}
				layer.confirm(msg,{icon: 7, title:'操作确认'}, function(index){
					layer.close(index);
					var index = layer.load();
					$.post("{:url('setPaymoneyGivepercent')}",{id:id,st:st},function(data){
						layer.close(index);
						dialog(data.msg,data.status);
						tableIns.reload()
					})
				});
		}
	{/if}
	</script>
</body>
</html>